home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 19 / Night Owl (The Best of Shareware)(NOPV 19)(1996).ISO / 007a / strakd10.zip / DTRAK.MEX next >
Text File  |  1995-11-18  |  10KB  |  316 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // StarTraker V1.00 [Count Display Module] (!)1995 Larry Monte\StarLab Systems
  4. //
  5. // MEX: Copyright 1990, 1995 by Lanius Corporation.  All rights reserved.
  6. //
  7. //
  8.  
  9. #define DO_DOORNAME 1
  10. #define DO_ENTRY    21
  11. #define DO_LAST     26
  12. #define DO_LASTUSR  44
  13. #define DO_RESET    62
  14.  
  15. #define LEN_DOORNAME 20
  16. #define LEN_ENTRY     5
  17. #define LEN_LAST     18
  18. #define LEN_LASTUSR  18
  19. #define LEN_RESET     9
  20. #define LEN_RECORD   77
  21.  
  22. #define CONFIG       "C:\\MAX\\STRAK\\STRAK.CTL"
  23. #define DAT_FILE     "C:\\MAX\\STRAK\\STRAK.DAT"
  24. #define ACCESS       "=Sysop "
  25.  
  26. #include <max.mh>
  27.  
  28. string: s, data, doorname, lastuser, fname, entry, reset, dstr, datestring;
  29. long: date, entery, fileoffset;
  30.  
  31. struct _doordat
  32. {
  33.   string: doorname, entry, last, lastuser, reset;
  34. };
  35.  
  36. array [1..50] of struct _doordat: di;
  37. array [1..50] of string: dc;
  38.  
  39. string intpad(int: i, int: len)
  40. {
  41.     return strpad(itostr(i), len, ' ');
  42. }
  43.  
  44. string unpackstr(ref string: s, int: ofs, int: len)
  45. {
  46.   return strtrim(substr(s, ofs, len), " ");
  47. }
  48.  
  49. void unpackdata(ref string: s)
  50. {
  51.   doorname := unpackstr(s, DO_DOORNAME, LEN_DOORNAME);
  52.   entry := unpackstr(s, DO_ENTRY, LEN_ENTRY);
  53.   dstr := unpackstr(s, DO_LAST, LEN_LAST);
  54.   lastuser := unpackstr(s, DO_LASTUSR, LEN_LASTUSR);
  55.   reset := unpackstr(s, DO_RESET, LEN_RESET);
  56. }
  57.  
  58. void packstr(ref string: s, string: u, int: ofs, int: len)
  59. {
  60.   int: c;
  61.   u := strpad(u, len, ' ');
  62.   for (c := 1; c <= len; c:=c+1)
  63.   {
  64.     s[ofs] := u[c];
  65.     ofs := ofs+1;
  66.   }
  67. }
  68.  
  69. void packdata(ref string: s, string: doordata)
  70. {
  71.   struct _stamp: now;
  72.   string: dstr;
  73.   int: pos;
  74.  
  75.   timestamp(now);
  76.   dstr := stamp_string(now);
  77.  
  78.   s := strpad("", LEN_RECORD, ' ');
  79.   packstr(s, doordata,      DO_DOORNAME,   LEN_DOORNAME);
  80.   entery := 0;
  81.   entry := strpadleft(ltostr(entery),5,' ');
  82.   reset := strtok(dstr, " \t",pos);
  83.   packstr(s, entry,         DO_ENTRY,      LEN_ENTRY);
  84.   packstr(s, dstr,          DO_LAST,       LEN_LAST);
  85.   packstr(s, usr.name,      DO_LASTUSR,    LEN_LASTUSR);
  86.   packstr(s, reset,         DO_RESET,      LEN_RESET);
  87.  
  88.   s[LEN_RECORD-1]:='\r';
  89.   s[LEN_RECORD-0]:='\n';
  90. }
  91.  
  92. int readdata(ref string: doordata)
  93. {
  94.   int: fd;
  95.   string: data, doorname;
  96.   fileoffset := -1;
  97.  
  98.   fd := open(DAT_FILE,IOPEN_READ);
  99.   if (fd<>-1)
  100.   {
  101.     int: done;
  102.     long: atofs;
  103.  
  104.     atofs := 0;
  105.     done := False;
  106.  
  107.     while (done = False AND (read(fd,data,LEN_RECORD)=LEN_RECORD))
  108.     {
  109.       doorname:=unpackstr(data,DO_DOORNAME,LEN_DOORNAME);
  110.       if (doorname=doordata)
  111.       {
  112.         fileoffset := atofs;
  113.         unpackdata(data);
  114.         done := True;
  115.       }
  116.       atofs := atofs+LEN_RECORD;
  117.     }
  118.     close(fd);
  119.   }
  120.   return True;
  121. }
  122.  
  123.  
  124. int writedata(string: doordata)
  125. {
  126.   int: fd;
  127.   string: data;
  128.  
  129.   packdata(data, doordata);
  130.   fd := open(DAT_FILE,IOPEN_RW);
  131.   if (fd = -1)
  132.   {
  133.     fd := open(DAT_FILE,IOPEN_RW|IOPEN_CREATE);
  134.     if (fd = -1)
  135.     {
  136.       print(COL_WHITE, "Error creating data file!\n\n");
  137.       menu_cmd(106,"");
  138.     }
  139.   }
  140.   if (fileoffset = -1)
  141.     fileoffset := seek(fd,0,SEEK_END);
  142.   seek(fd,fileoffset,SEEK_SET);
  143.   write(fd,data,LEN_RECORD);
  144.   close(fd);
  145. }
  146.  
  147. void main()
  148. {
  149.  
  150.   int: recs, numdoors, ignore;
  151.   int: dd, ch, fd, i, confirm, sysop_functions;
  152.   string: data, tagno, doordata;
  153.   char: nonstop;
  154.   long: atofs;
  155.  
  156.   reset_more(nonstop);
  157.   id.instant_video := 1;
  158.  
  159.   fd := open(DAT_FILE,IOPEN_READ|IOPEN_CREATE);
  160.   if (fd<>-1)
  161.   {
  162.  
  163.     atofs := 0;
  164.     print(AVATAR_CLS,
  165.           COL_WHITE, "    ─═════─  ─═════─   ─═══─   ─════─   ─═════─   ─════─    ─═══─   ═─   ─═\n",
  166.           COL_LCYAN, "    ══         ═══    ══   ══  ══   ══    ═══     ══   ══  ══   ══  ══  ══\n",
  167.        COL_LMAGENTA, "    ══════─    ═══    ══───══  ══───══    ═══     ══───══  ══───══  ══─══\n",
  168.           COL_LBLUE, "         ══    ═══    ══   ══  ══  ══     ═══     ══  ══   ══   ══  ══  ══\n",
  169.            COL_BLUE, "    ▀▀▀▀▀▀▀    ▀▀▀    ▀▀   ▀▀  ▀▀   ▀▀    ▀▀▀     ▀▀   ▀▀  ▀▀   ▀▀  ▀▀   ▀▀\n",
  170.            COL_GRAY, "───────────────────────────────────────────────────────────────────────────────\n",
  171.    COL_YELLOWONBLUE, "  StarTrak! Door Activity Tracker V1.00   (!)1995 Larry Monte/StarLab Systems  \n",
  172.            COL_GRAY, "───────────────────────────────────────────────────────────────────────────────\n",
  173.            COL_BLUE, "╔═════════════════════╤═══════╤══════════════════╤══════════════════╤═════════╗\n",
  174.                      "║ ", COL_WHITE, "DoorName            ", COL_BLUE, "│", COL_GREEN, "Entries", COL_BLUE, "│", COL_LCYAN, "Last Date Entered ", COL_BLUE, "│", COL_GRAY, "Last User To Play ",  COL_BLUE, "│", COL_CYAN,"ReSet On ", COL_BLUE, "║\n",
  175.                      "╠═════════════════════╪═══════╪══════════════════╪══════════════════╪═════════╣\n");
  176.  
  177.     while (read(fd,data,LEN_RECORD)=LEN_RECORD AND do_more(nonstop, COL_CYAN))
  178.     {
  179.       unpackdata(data);
  180.  
  181.       print(COL_BLUE, "║ ", COL_WHITE, strpad(doorname,20,' '),
  182.             COL_BLUE, "│", COL_GREEN, strpadleft(entry,7,' '),
  183.             COL_BLUE, "│", COL_LCYAN, strpad(dstr,18,' '),
  184.             COL_BLUE, "│", COL_GRAY, strpad(lastuser,18,' '),
  185.             COL_BLUE, "│", COL_CYAN, strpad(reset,9,' '), COL_BLUE, "║\n");
  186.     }
  187.     i:=i+1;
  188.     atofs := atofs+LEN_RECORD;
  189.   }
  190.   close(fd);
  191.   print(COL_BLUE, "╚═════════════════════╧═══════╧══════════════════╧══════════════════╧═════════╝\n");
  192.   if (privok(ACCESS) = TRUE)
  193.   {
  194.     sysop_functions := input_list("|YN", 0, "", "", "\x16\x01\x0bDo SysOp Maintenance");
  195.     if (sysop_functions = 'Y')
  196.     {
  197.       print(AVATAR_CLS);
  198.       print(COL_WHITE, "StarTrak Sysop Menu \n\n");
  199.       print(COL_YELLOW, "Data exists for the following doors:\n");
  200.       fd:= open(DAT_FILE,IOPEN_READ);
  201.       if (fd<>-1)
  202.       {
  203.         int: pos, done;
  204.  
  205.         nonstop :=0;
  206.         reset_more(nonstop);
  207.         done := FALSE;
  208.         i := 1;
  209.         atofs := 0;
  210.  
  211.         print("\n", COL_YELLOW, "TagNumber   ", COL_LBLUE, "DoorName\n");
  212.         print(       COL_LCYAN, "─────────   ───────────────────────────────\n");
  213.         while (read(fd,s,LEN_RECORD)=LEN_RECORD AND do_more(nonstop, COL_CYAN))
  214.         {
  215.           dc[i] := unpackstr(s, DO_DOORNAME, LEN_DOORNAME);
  216.           print(COL_YELLOW, intpad(i,12), COL_LBLUE, dc[i], "\n");
  217.           i:=i+1;
  218.           atofs := atofs+LEN_RECORD;
  219.           seek(fd,atofs,SEEK_SET);
  220.         }
  221.       }
  222.       close(fd);
  223.       ch := input_list("|RKSN", 0, "", "", "\n\x16\x01\x0e R\x16\x01\x0beset Single Counter / \x16\x01\x0eK\x16\x01\x0bill A Door Counter / \x16\x01\x0eS\x16\x01\x0btart new DATA file / Do \x16\x01\x0eN\x16\x01\x0bothing\n");
  224.       if (ch = 'E')
  225.       {
  226.         confirm := input_list("|YN", 0, "", "", "\x16\x01\x0bKill everything. Are you SURE");
  227.         if (confirm = 'Y')
  228.         {
  229.           remove(DAT_FILE);
  230.           fd:= open(DAT_FILE,IOPEN_CREATE);
  231.           if (fd = -1)
  232.           {
  233.             print(COL_WHITE, "Error creating data file!\n\n");
  234.             menu_cmd(106,"");
  235.           }
  236.           close(fd);
  237.         }
  238.       }
  239.       if (ch = 'R')
  240.       {
  241.         input_str(tagno, INPUT_NLB_LINE, 0, 2, "Enter Door TagNumber");
  242.         i := strtoi(tagno);
  243.         doordata := dc[i];
  244.         confirm := input_list("|YN", 0, "", "", "\x16\x01\x0bReset counter. Are you SURE");
  245.         if (confirm = 'Y')
  246.         {
  247.           readdata(doordata);
  248.           writedata(doordata);
  249.         }
  250.       }
  251.       if (ch = 'K')
  252.       {
  253.         input_str(tagno, INPUT_NLB_LINE, 0, 2, "Enter Door TagNumber");
  254.         i := strtoi(tagno);
  255.         doordata := dc[i];
  256.         confirm := input_list("|YN", 0, "", "", "\x16\x01\x0bKill entry. Are you SURE");
  257.         if (confirm = 'Y')
  258.         {
  259.           fd := open(DAT_FILE,IOPEN_READ);
  260.           if (fd<>-1)
  261.           {
  262.             int: done;
  263.  
  264.             done := False;
  265.             i := 1;
  266.  
  267.             while (read(fd,s,LEN_RECORD)=LEN_RECORD)
  268.             {
  269.               di[i].doorname := unpackstr(s, DO_DOORNAME, LEN_DOORNAME);
  270.               di[i].entry := unpackstr(s, DO_ENTRY, LEN_ENTRY);
  271.               di[i].last := unpackstr(s, DO_LAST, LEN_LAST);
  272.               di[i].lastuser := unpackstr(s, DO_LASTUSR, LEN_LASTUSR);
  273.               di[i].reset := unpackstr(s, DO_RESET, LEN_RESET);
  274.               if (doordata = di[i].doorname)
  275.               {
  276.                 ignore := i;
  277.               }
  278.               i:=i+1;
  279.               numdoors := i;
  280.             }
  281.           }
  282.           close(fd);
  283.           fd := open(DAT_FILE,IOPEN_WRITE|IOPEN_CREATE);
  284.           if (fd = -1)
  285.           {
  286.             print(COL_WHITE, "Error creating data file!\n\n");
  287.             menu_cmd(106,"");
  288.           }
  289.           atofs :=0;
  290.           for (i:=1;i < numdoors;i:=i+1)
  291.           {
  292.             if (i<>ignore AND di[i].doorname <> "")
  293.             {
  294.               s := strpad("", LEN_RECORD, ' ');
  295.               packstr(s, di[i].doorname,      DO_DOORNAME,   LEN_DOORNAME);
  296.               packstr(s, di[i].entry,         DO_ENTRY,      LEN_ENTRY);
  297.               packstr(s, di[i].last,          DO_LAST,       LEN_LAST);
  298.               packstr(s, di[i].lastuser,      DO_LASTUSR,    LEN_LASTUSR);
  299.               packstr(s, di[i].reset,         DO_RESET,      LEN_RESET);
  300.               s[LEN_RECORD-1]:='\r';
  301.               s[LEN_RECORD-0]:='\n';
  302.               seek(fd,atofs,SEEK_SET);
  303.               write(fd,s,LEN_RECORD);
  304.               atofs := atofs+LEN_RECORD;
  305.             }
  306.           }
  307.           close(fd);
  308.         }
  309.       }
  310.     }
  311.   }
  312.   menu_cmd(106,"");
  313. }
  314.  
  315.  
  316.